using AjaxControlToolkit;
using ASP;
using ClassLibrary.BusinessLayer.Facade;
using IPMS.AccessAuth;
using IPMS.BLL;
using Resources;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Drawing;
using System.Globalization;
using System.Threading;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web;
using SysOperationLayer.DBHandle;
using SysComm;

public partial class ProjectInfo : Page, IRequiresSessionState
{
    LogDB m_logdb = new LogDB();
    private string projectCode = null;
    private string projectgroupid = null;
    private string projecttype = null;
    protected int Add(object sender, EventArgs e)
    {
        //Auth canAdd = new Auth(this.Session["UserId"].ToString(), string.Empty, "ProjectInfo");
        Project pj = new Project();
        List<string> values = new List<string>();
        int Count = pj.GetLicenseCount();

        if ((Count <= pj.GetUserProjectCount(this.Page.User.Identity.Name.ToString())) & (Count != 0x1a))
        {
            this.lblError.Visible = true;
            values.Add(Count.ToString());
            this.lblError.Text = IPDataFormat.GenerateMessage(Messages.mProjectCount.ToString(), values);
            return -1;
        }

        //if (!canAdd.CanAdd())
        //{
        //    this.lblError.Visible = true;
       //     this.lblError.Text = Messages.mNoAdd.ToString();
        //    return -1;
        //}

        this.clearText();
        this.setButtons("new");
        this.setTextReadOnly(false);
        this.txtProjectCode.Focus();
        this.Session["IsNewRecord"] = "Yes";
        this.GetProjectDefault();
        this.EnabledDisabledPriority("New");
        if (this.chkFirstFiling.Checked)
        {
            this.txtFilingDate.CssClass = "required";
            this.RequiredFieldValidator5.Enabled = true;
        }
        else
        {
            this.txtFilingDate.CssClass = "";
            this.RequiredFieldValidator5.Enabled = false;
        }
        return 0;
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        int iReturn = 0;
        iReturn = this.Add(sender, e);
    }

    protected void btnAgent_Click(object sender, EventArgs e)
    {
        if ((this.Session["SelectedAgent"] != null) && (this.Session["SelectedAgent"].ToString() != ""))
        {
            string Result = this.Session["SelectedAgent"].ToString();
            AgentsFacade facade = new AgentsFacade();
            SqlParameter[] sqlparam = new SqlParameter[4];
            sqlparam[0] = new SqlParameter();
            sqlparam[0].ParameterName = "@Agent";
            sqlparam[0].Value = Result;
            sqlparam[1] = new SqlParameter();
            sqlparam[1].ParameterName = "@Name";
            sqlparam[1].Value = "";
            sqlparam[2] = new SqlParameter();
            sqlparam[2].ParameterName = "@ChineseName";
            sqlparam[2].Value = "";
            sqlparam[3] = new SqlParameter();
            sqlparam[3].ParameterName = "@ContactPerson";
            sqlparam[3].Value = "";
            DbParameter[] param = sqlparam;
            DataTable dt = facade.GetsAgents("_IPMS_AgentSelect_SP", param);
            this.txtAgent.Text = dt.Rows[0]["Agent"].ToString();
            this.txtAgentName.Text = dt.Rows[0]["Name"].ToString();
            this.txtAgentChineseName.Text = dt.Rows[0]["ChineseName"].ToString();
            this.txtAgentContactPerson.Text = dt.Rows[0]["ContactPerson"].ToString();
            this.txtAgentAddress.Text = dt.Rows[0]["Address"].ToString();
            this.txtAgentWebSite.Text = dt.Rows[0]["WebSite"].ToString();
            this.txtAgentFaxNo.Text = dt.Rows[0]["Fax"].ToString();
            this.txtAgentPhoneNo.Text = dt.Rows[0]["Phone"].ToString();
            this.txtAgentPhoneNo2.Text = dt.Rows[0]["Phone2"].ToString();
            this.txtAgentContactPerson2.Text = dt.Rows[0]["ContactPerson2"].ToString();
            this.txtAgentFaxNo2.Text = dt.Rows[0]["Fax2"].ToString();
            this.txtAgentEmailAddress.Text = dt.Rows[0]["EmailAddress"].ToString();
            this.txtAgentEmailAddress2.Text = dt.Rows[0]["EmailAddress2"].ToString();
            this.Session.Remove("SelectedAgent");
        }
    }

    protected void btnAgentSetBlank_Click(object sender, EventArgs e)
    {
        this.txtAgent.Text = string.Empty;
        this.txtAgentName.Text = string.Empty;
        this.txtAgentChineseName.Text = string.Empty;
        this.txtAgentContactPerson.Text = string.Empty;
        this.txtAgentAddress.Text = string.Empty;
        this.txtAgentWebSite.Text = string.Empty;
        this.txtAgentFaxNo.Text = string.Empty;
        this.txtAgentPhoneNo.Text = string.Empty;
        this.txtAgentPhoneNo2.Text = string.Empty;
        this.txtAgentContactPerson2.Text = string.Empty;
        this.txtAgentFaxNo2.Text = string.Empty;
        this.txtAgentEmailAddress.Text = string.Empty;
        this.txtAgentEmailAddress2.Text = string.Empty;
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        this.setButtons(string.Empty);
        this.setTextReadOnly(true);
        this.PanelGeneral.Visible = false;
        this.PanelAgent.Visible = false;
        this.PanelClient.Visible = false;
        this.PanelOther.Visible = false;
        this.PrjInfoPanel.Visible = false;
        this.ProjectListPanel.Visible = true;
        this.ibExpenditure.Visible = false;
        this.ibProjectHeaderInfo.Visible = false;
        this.ibProjectInfo.Visible = false;
        this.ibViewDoc.Visible = false;
        this.lblNoRecords.Visible = false;
        try
        {
            if (base.Request.QueryString["np"].ToString() == "1")
            {
            }
        }
        catch (Exception)
        {
        }
    }

    protected void btnClient_Click(object sender, EventArgs e)
    {
        if ((this.Session["SelectedClient"] != null) && (this.Session["SelectedClient"].ToString() != ""))
        {
            string Result = this.Session["SelectedClient"].ToString();
            AgentsFacade facade = new AgentsFacade();
            SqlParameter[] sqlparam = new SqlParameter[4];
            sqlparam[0] = new SqlParameter();
            sqlparam[0].ParameterName = "@Client";
            sqlparam[0].Value = Result;
            sqlparam[1] = new SqlParameter();
            sqlparam[1].ParameterName = "@Name";
            sqlparam[1].Value = "";
            sqlparam[2] = new SqlParameter();
            sqlparam[2].ParameterName = "@ChineseName";
            sqlparam[2].Value = "";
            sqlparam[3] = new SqlParameter();
            sqlparam[3].ParameterName = "@ContactPerson";
            sqlparam[3].Value = "";

            DbParameter[] param = sqlparam;
            DataTable dt = facade.GetsAgents("_IPMS_ClientSelect_SP", param);
            this.txtClient.Text = dt.Rows[0]["Client"].ToString();
            this.txtClientName.Text = dt.Rows[0]["Name"].ToString();
            this.txtClientChineseName.Text = dt.Rows[0]["ChineseName"].ToString();
            this.txtClientContactPerson.Text = dt.Rows[0]["ContactPerson"].ToString();
            this.txtClientAddress.Text = dt.Rows[0]["Address"].ToString();
            this.txtClientWebSite.Text = dt.Rows[0]["WebSite"].ToString();
            this.txtClientFax.Text = dt.Rows[0]["Fax"].ToString();
            this.txtClientPhone.Text = dt.Rows[0]["Phone"].ToString();
            this.txtClientPhone2.Text = dt.Rows[0]["Phone2"].ToString();
            this.txtClientContactPerson2.Text = dt.Rows[0]["ContactPerson2"].ToString();
            this.txtClientFax2.Text = dt.Rows[0]["Fax2"].ToString();
            this.txtClientEmailAddress.Text = dt.Rows[0]["EmailAddress"].ToString();
            this.txtClientEmailAddress2.Text = dt.Rows[0]["EmailAddress2"].ToString();
            this.Session.Remove("SelectedClient");
        }
    }

    protected void btnClientSetBlank_Click(object sender, EventArgs e)
    {
        this.txtClient.Text = string.Empty;
        this.txtClientName.Text = string.Empty;
        this.txtClientChineseName.Text = string.Empty;
        this.txtClientContactPerson.Text = string.Empty;
        this.txtClientAddress.Text = string.Empty;
        this.txtClientWebSite.Text = string.Empty;
        this.txtClientFax.Text = string.Empty;
        this.txtClientPhone.Text = string.Empty;
        this.txtClientPhone2.Text = string.Empty;
        this.txtClientContactPerson2.Text = string.Empty;
        this.txtClientFax2.Text = string.Empty;
        this.txtClientEmailAddress.Text = string.Empty;
        this.txtClientEmailAddress2.Text = string.Empty;
    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        Auth canDelete = new Auth(this.Session["UserId"].ToString(), string.Empty, "ProjectInfo");
        if (!canDelete.CanDelete())
        {
            this.lblError.Visible = true;
            this.lblError.Text = Messages.mNoDelete.ToString();
        }
        else
        {
            try
            {
                this.ODSProjects.DeleteMethod = "Delete";
                this.ODSProjects.DeleteParameters["IsDelete"].DefaultValue = "true";
                this.ODSProjects.DeleteParameters["DeleteBy"].DefaultValue = this.Page.User.Identity.Name.ToString();
                this.ODSProjects.DeleteParameters["DeleteIP"].DefaultValue = HttpContext.Current.Request.UserHostAddress;
                this.ODSProjects.DeleteParameters["Original_ProjectCode"].DefaultValue = this.txtProjectCode.Text.ToString();
                this.ODSProjects.Delete();
                this.GridView1.DataBind();
                this.btnCancel_Click(sender, e);
                if (this.GridView1.Rows.Count == 0)
                {
                    this.lblNoRecords.Visible = true;
                }
                else
                {
                    this.lblNoRecords.Visible = false;
                }
                m_logdb.writeSucLog(SysUtil.m_functiong_project, "delete project succeed!");
            }
            catch (Exception)
            {
                this.chkForOperation.Checked = true;
                this.lblError.Visible = true;
                this.lblError.Text = Messages.mHeadingInfoExist.ToString();
                m_logdb.writeFaileLog(SysUtil.m_functiong_project, "delete project faile!");
            }
        }
    }

    protected void btnRestore_Click(object sender, EventArgs e)
    {
        Project project = new Project();

        string updateBy = this.Page.User.Identity.Name.ToString();
        string updateIP = HttpContext.Current.Request.UserHostAddress;
        string projectCode =  this.txtProjectCode.Text.ToString().Trim();

        bool isSuccess = project.Update(false, updateBy, updateIP, projectCode);

        if (isSuccess)
        {
            this.GridView1.DataBind();
            this.btnCancel_Click(sender, e);
            if (this.GridView1.Rows.Count == 0)
            {
                this.lblNoRecords.Visible = true;
            }
            else
            {
                this.lblNoRecords.Visible = false;
            }
        }
    }

    protected void btnPGI_Click(object sender, EventArgs e)
    {
        if ((this.Session["SelectedProjectGroup"] != null) && (this.Session["SelectedProjectGroup"].ToString() != ""))
        {
            this.txtProjectGroupID.Text = this.Session["SelectedProjectGroup"].ToString();
            this.GetProjectDefault();
            this.EnabledDisabledPriority("New");
        }
    }

    protected void btnProjectClassSetBlank_Click(object sender, EventArgs e)
    {
        this.txtProjectClass.Text = string.Empty;
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        string bIsNewRec = this.Session["IsNewRecord"].ToString();
        try
        {
            if ((this.txtPatentNumber.Text.Length != 0) && (IPDataFormat.FormatDateTime(this.txtGrantDate.Text) == ""))
            {
                throw new Exception(Messages.mGrantDate_Required.ToString());
            }
            if ((this.txtPatentNumber.Text.Length != 0) 
                && (IPDataFormat.GetValidDateTime(IPDataFormat.ConvertDateFormat(this.txtFilingDate.Text.ToString(), 1)) 
                    >= IPDataFormat.GetValidDateTime(IPDataFormat.ConvertDateFormat(this.txtGrantDate.Text.ToString(), 1))))
            {
                throw new Exception(Messages.mGrantDate_GE_FilingDate.ToString());
            }
            if (this.txtProjectCode.Text.Contains("&"))
            {
                throw new Exception(Messages.mInvalidProjectCode.ToString());
            }
            if ((this.txtPatentNumber.Text.Length != 0) && (this.txtGrantDate.Text.Length == 0))
            {
                throw new Exception(Messages.mGrantDateCannotBeNull.ToString());
            }
            if (bIsNewRec == "Yes")
            {
                this.ODSProjects.InsertMethod = "Insert";
                this.ODSProjects.InsertParameters["ProjectCode"].DefaultValue = this.txtProjectCode.Text.ToString();
                this.ODSProjects.InsertParameters["Type"].DefaultValue = this.txtType.Text;
                this.ODSProjects.InsertParameters["Status"].DefaultValue = this.ddlStatus.SelectedValue.ToString();
                this.ODSProjects.InsertParameters["Country"].DefaultValue = this.ddlCountry.SelectedValue.ToString();
                this.ODSProjects.InsertParameters["Agent"].DefaultValue = this.txtAgent.Text.ToString();
                this.ODSProjects.InsertParameters["Title"].DefaultValue = this.txtTitleSubject.Text.ToString();
                this.ODSProjects.InsertParameters["Applicant"].DefaultValue = this.txtApplicant.Text.ToString();
                this.ODSProjects.InsertParameters["Inventor"].DefaultValue = this.txtInventor.Text.ToString();
                this.ODSProjects.InsertParameters["ApplicationNo"].DefaultValue = this.txtApplicationNo.Text.ToString();
                this.ODSProjects.InsertParameters["PatentNumber"].DefaultValue = this.txtPatentNumber.Text.ToString();
                this.ODSProjects.InsertParameters["PriorityDate"].DefaultValue = IPDataFormat.ConvertDateFormat(this.txtPriorityDate.Text.ToString(), 1);
                this.ODSProjects.InsertParameters["PriorityCountry"].DefaultValue = this.ddlPriorityCountry.SelectedValue.ToString();
                this.ODSProjects.InsertParameters["ClientName"].DefaultValue = this.txtClient.Text.ToString();
                this.ODSProjects.InsertParameters["FilingDate"].DefaultValue = IPDataFormat.ConvertDateFormat(this.txtFilingDate.Text.ToString(), 1);
                this.ODSProjects.InsertParameters["GrantDate"].DefaultValue = IPDataFormat.ConvertDateFormat(this.txtGrantDate.Text.ToString(), 1);
                this.ODSProjects.InsertParameters["FirstFilingYN"].DefaultValue = this.chkFirstFiling.Checked ? "true" : "false";
                this.ODSProjects.InsertParameters["ProjectGroupID"].DefaultValue = this.txtProjectGroupID.Text.ToString();
                this.ODSProjects.InsertParameters["PublicationNumber"].DefaultValue = this.txtPublicationNumber.Text.ToString();
                this.ODSProjects.InsertParameters["Remark"].DefaultValue = this.txtRemarks.Text.ToString();
                this.ODSProjects.InsertParameters["CreateBy"].DefaultValue = this.Page.User.Identity.Name.ToString();
                this.ODSProjects.InsertParameters["UpdateBy"].DefaultValue = this.Page.User.Identity.Name.ToString();
                this.ODSProjects.InsertParameters["OwnerGroupID"].DefaultValue = this.Session["OwnerGroupId"].ToString();
                this.ODSProjects.InsertParameters["ProjectClass"].DefaultValue = this.txtProjectClass.Text.ToString();
                this.ODSProjects.InsertParameters["Priority"].DefaultValue = this.chkPriority.Checked ? "true" : "false";
                this.ODSProjects.InsertParameters["PCTYN"].DefaultValue = this.chkPCT.Checked ? "true" : "false";
                this.ODSProjects.InsertParameters["AgentContactPerson3"].DefaultValue = this.txtAgentContactPerson3.Text.ToString();
                this.ODSProjects.InsertParameters["AgentContactFax3"].DefaultValue = this.txtAgentContactFax3.Text.ToString();
                this.ODSProjects.InsertParameters["AgentContactPhone3"].DefaultValue = this.txtAgentContactPhone3.Text.ToString();
                this.ODSProjects.InsertParameters["AgentContactEmailAddress3"].DefaultValue = this.txtAgentContactEmail3.Text.ToString();
                this.ODSProjects.InsertParameters["AgentContactPerson4"].DefaultValue = this.txtAgentContactPerson4.Text.ToString();
                this.ODSProjects.InsertParameters["AgentContactFax4"].DefaultValue = this.txtAgentContactFax4.Text.ToString();
                this.ODSProjects.InsertParameters["AgentContactPhone4"].DefaultValue = this.txtAgentContactPhone4.Text.ToString();
                this.ODSProjects.InsertParameters["AgentContactEmailAddress4"].DefaultValue = this.txtAgentContactEmail4.Text.ToString();
                this.ODSProjects.InsertParameters["ClientContactPerson3"].DefaultValue = this.txtClientContactPerson3.Text.ToString();
                this.ODSProjects.InsertParameters["ClientContactFax3"].DefaultValue = this.txtClientContactFax3.Text.ToString();
                this.ODSProjects.InsertParameters["ClientContactPhone3"].DefaultValue = this.txtClientContactPhone3.Text.ToString();
                this.ODSProjects.InsertParameters["ClientContactEmailAddress3"].DefaultValue = this.txtClientContactEmail3.Text.ToString();
                this.ODSProjects.InsertParameters["ClientContactPerson4"].DefaultValue = this.txtClientContactPerson4.Text.ToString();
                this.ODSProjects.InsertParameters["ClientContactFax4"].DefaultValue = this.txtClientContactFax4.Text.ToString();
                this.ODSProjects.InsertParameters["ClientContactPhone4"].DefaultValue = this.txtClientContactPhone4.Text.ToString();
                this.ODSProjects.InsertParameters["ClientContactEmailAddress4"].DefaultValue = this.txtClientContactEmail4.Text.ToString();
                this.ODSProjects.InsertParameters["CreateIP"].DefaultValue = HttpContext.Current.Request.UserHostAddress;
                this.ODSProjects.Insert();
                new ProjectSupervisor(this.txtProjectCode.Text.ToString(), this.Page.User.Identity.Name.ToString(), this.Session["OwnerGroupId"].ToString()).CreateResponsiblePerson();
            }
            else
            {
                this.ODSProjects.UpdateMethod = "Update";
                this.ODSProjects.UpdateParameters["Type"].DefaultValue = this.txtType.Text;
                this.ODSProjects.UpdateParameters["Status"].DefaultValue = this.ddlStatus.SelectedValue.ToString();
                this.ODSProjects.UpdateParameters["Country"].DefaultValue = this.ddlCountry.SelectedValue.ToString();
                this.ODSProjects.UpdateParameters["Agent"].DefaultValue = this.txtAgent.Text.ToString();
                this.ODSProjects.UpdateParameters["Title"].DefaultValue = this.txtTitleSubject.Text.ToString();
                this.ODSProjects.UpdateParameters["Applicant"].DefaultValue = this.txtApplicant.Text.ToString();
                this.ODSProjects.UpdateParameters["Inventor"].DefaultValue = this.txtInventor.Text.ToString();
                this.ODSProjects.UpdateParameters["ApplicationNo"].DefaultValue = this.txtApplicationNo.Text.ToString();
                this.ODSProjects.UpdateParameters["PatentNumber"].DefaultValue = this.txtPatentNumber.Text.ToString();
                this.ODSProjects.UpdateParameters["PriorityDate"].DefaultValue = IPDataFormat.ConvertDateFormat(this.txtPriorityDate.Text.ToString(), 1);
                this.ODSProjects.UpdateParameters["PriorityCountry"].DefaultValue = this.ddlPriorityCountry.SelectedValue.ToString();
                this.ODSProjects.UpdateParameters["ClientName"].DefaultValue = this.txtClient.Text.ToString();
                this.ODSProjects.UpdateParameters["FilingDate"].DefaultValue = IPDataFormat.ConvertDateFormat(this.txtFilingDate.Text.ToString(), 1);
                this.ODSProjects.UpdateParameters["GrantDate"].DefaultValue = IPDataFormat.ConvertDateFormat(this.txtGrantDate.Text.ToString(), 1);
                this.ODSProjects.UpdateParameters["FirstFilingYN"].DefaultValue = this.chkFirstFiling.Checked ? "true" : "false";
                this.ODSProjects.UpdateParameters["ProjectGroupID"].DefaultValue = this.txtProjectGroupID.Text.ToString();
                this.ODSProjects.UpdateParameters["PublicationNumber"].DefaultValue = this.txtPublicationNumber.Text.ToString();
                this.ODSProjects.UpdateParameters["Remark"].DefaultValue = this.txtRemarks.Text.ToString();
                this.ODSProjects.UpdateParameters["UpdateBy"].DefaultValue = this.Page.User.Identity.Name.ToString();
                this.ODSProjects.UpdateParameters["OwnerGroupID"].DefaultValue = this.Session["OwnerGroupId"].ToString();
                this.ODSProjects.UpdateParameters["Original_ProjectCode"].DefaultValue = this.txtProjectCode.Text.ToString();
                this.ODSProjects.UpdateParameters["ProjectClass"].DefaultValue = this.txtProjectClass.Text.ToString();
                this.ODSProjects.UpdateParameters["Priority"].DefaultValue = this.chkPriority.Checked ? "true" : "false";
                this.ODSProjects.UpdateParameters["PCTYN"].DefaultValue = this.chkPCT.Checked ? "true" : "false";
                this.ODSProjects.UpdateParameters["AgentContactPerson3"].DefaultValue = this.txtAgentContactPerson3.Text.ToString();
                this.ODSProjects.UpdateParameters["AgentContactFax3"].DefaultValue = this.txtAgentContactFax3.Text.ToString();
                this.ODSProjects.UpdateParameters["AgentContactPhone3"].DefaultValue = this.txtAgentContactPhone3.Text.ToString();
                this.ODSProjects.UpdateParameters["AgentContactEmailAddress3"].DefaultValue = this.txtAgentContactEmail3.Text.ToString();
                this.ODSProjects.UpdateParameters["AgentContactPerson4"].DefaultValue = this.txtAgentContactPerson4.Text.ToString();
                this.ODSProjects.UpdateParameters["AgentContactFax4"].DefaultValue = this.txtAgentContactFax4.Text.ToString();
                this.ODSProjects.UpdateParameters["AgentContactPhone4"].DefaultValue = this.txtAgentContactPhone4.Text.ToString();
                this.ODSProjects.UpdateParameters["AgentContactEmailAddress4"].DefaultValue = this.txtAgentContactEmail4.Text.ToString();
                this.ODSProjects.UpdateParameters["ClientContactPerson3"].DefaultValue = this.txtClientContactPerson3.Text.ToString();
                this.ODSProjects.UpdateParameters["ClientContactFax3"].DefaultValue = this.txtClientContactFax3.Text.ToString();
                this.ODSProjects.UpdateParameters["ClientContactPhone3"].DefaultValue = this.txtClientContactPhone3.Text.ToString();
                this.ODSProjects.UpdateParameters["ClientContactEmailAddress3"].DefaultValue = this.txtClientContactEmail3.Text.ToString();
                this.ODSProjects.UpdateParameters["ClientContactPerson4"].DefaultValue = this.txtClientContactPerson4.Text.ToString();
                this.ODSProjects.UpdateParameters["ClientContactFax4"].DefaultValue = this.txtClientContactFax4.Text.ToString();
                this.ODSProjects.UpdateParameters["ClientContactPhone4"].DefaultValue = this.txtClientContactPhone4.Text.ToString();
                this.ODSProjects.UpdateParameters["ClientContactEmailAddress4"].DefaultValue = this.txtClientContactEmail4.Text.ToString();
                this.ODSProjects.UpdateParameters["UpdateIP"].DefaultValue = HttpContext.Current.Request.UserHostAddress;
                //this.ODSProjects.UpdateParameters["UpdateDate"].DefaultValue = DateTime.Now.ToString();
                this.ODSProjects.Update();
            }
            this.ODSProjects.Select();
            this.Session["fromReminder"] = "1";
            string RefreshParent_javaScript = "<script type='text/javascript' language='javascript'> \n";
            string strname = RefreshParent_javaScript;
            RefreshParent_javaScript = (strname + "window.parent.location = 'Default.aspx?projectGroupId=" + this.txtProjectGroupID.Text.ToString() + "&projectCode=" + this.txtProjectCode.Text.ToString() + "&projectType=" + this.txtType.Text + "&np=0'") + "</script>";
            base.ClientScript.RegisterStartupScript(this.Page.GetType(), "RefreshParent", RefreshParent_javaScript);
            if (bIsNewRec == "Yes")
            {
                m_logdb.writeSucLog(SysUtil.m_functiong_project, "add project succeed!");
            }
            else
            {
                m_logdb.writeSucLog(SysUtil.m_functiong_project, "update project succeed!");
            }
        }
        catch (Exception ex)
        {
            List<string> lstValues = new List<string>();
            lstValues.Add(Strings.ProjectInformation.ToString());
            //this.lblError.Text = IPDataFormat.GenerateMessage(ex, lstValues);
            this.lblError.Text = ex.Message.ToString();
            this.lblError.Visible = true;
            this.chkForOperation.Checked = true;
            if (bIsNewRec == "Yes")
            {
                m_logdb.writeFaileLog(SysUtil.m_functiong_project, "add project faile!");
            }
            else
            {
                m_logdb.writeFaileLog(SysUtil.m_functiong_project, "update project faile!");
            }
        }
        this.chkForUpdate.Checked = false;
    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        Auth canUpdate = new Auth(this.Session["UserId"].ToString(), string.Empty, "ProjectInfo");
        if (!canUpdate.CanUpdate())
        {
            this.lblError.Visible = true;
            this.lblError.Text = Messages.mNoEdit.ToString();
        }
        else
        {
            this.setButtons("modify");
            this.setTextReadOnly(false);
            this.txtProjectCode.ReadOnly = true;
            this.txtProjectCode.Enabled = false;
            this.btnPGI.Enabled = false;
            this.ddlCountry.Focus();
            this.txtType.Enabled = false;
            this.Session["IsNewRecord"] = "No";
            this.chkForUpdate.Checked = true;
            this.chkForOperation.Checked = true;
            this.GetProjectDefault();
            this.EnabledDisabledPriority("Edit");
            this.PCTProcess(true);
            this.Page.SetFocus("txtTitleSubject");
        }
    }

    protected void chkFirstFiling_CheckedChanged(object sender, EventArgs e)
    {
        if (this.chkFirstFiling.Checked)
        {
            this.txtFilingDate.CssClass = "required";
            this.RequiredFieldValidator5.Enabled = true;
            this.txtFilingDate.Enabled = true;
            if (this.txtFilingDate.Text == "")
            {
                this.txtFilingDate.Text = IPDataFormat.ConvertDateFormat(DateTime.Now.ToShortDateString(), 2);
            }
            this.txtPriorityDate.Text = "";
        }
        else
        {
            this.txtFilingDate.CssClass = "";
            this.RequiredFieldValidator5.Enabled = false;
            this.txtFilingDate.Enabled = true;
        }
    }

    protected void chkPCT_CheckedChanged(object sender, EventArgs e)
    {
        this.PCTProcess(false);
        if (!this.chkPCT.Checked)
        {
            this.txtPriorityDate.Text = "";
        }
        if (this.chkPCT.Checked)
        {
            this.txtPriorityDate.Text = this.txtFilingDate.Text;
        }
    }

    protected void chkPriority_CheckedChanged(object sender, EventArgs e)
    {
        if (this.chkPriority.Checked)
        {
            try
            {
                ProjectGroupClass runMethod = new ProjectGroupClass();
                runMethod.GetProjectGroupInfo(this.txtProjectGroupID.Text);
                this.txtPriorityDate.Text = IPDataFormat.ConvertDateFormat(runMethod.FirstFilingDate, 2);
                this.ddlPriorityCountry.ClearSelection();
                this.ddlPriorityCountry.Items.FindByValue(this.Session["PCTCountry"].ToString()).Selected = true;
            }
            catch
            {
                this.ddlPriorityCountry.SelectedIndex = -1;
                this.ddlPriorityCountry.Items.FindByValue("").Selected = true;
            }
        }
        else
        {
            this.ddlPriorityCountry.SelectedIndex = -1;
            this.ddlPriorityCountry.Items.FindByValue("").Selected = true;
            this.txtPriorityDate.Text = "";
            this.txtPriorityDate.Enabled = true;
        }
    }

    private void clearText()
    {
        this.txtProjectCode.Text = string.Empty;
        this.txtType.Text = "";
        this.ddlStatus.SelectedIndex = 0;
        this.ddlCountry.SelectedIndex = 0;
        this.txtAgent.Text = string.Empty;
        this.chkPCT.Checked = false;
        this.txtAgentName.Text = string.Empty;
        this.txtAgentChineseName.Text = string.Empty;
        this.txtAgentContactPerson.Text = string.Empty;
        this.txtAgentAddress.Text = string.Empty;
        this.txtAgentWebSite.Text = string.Empty;
        this.txtAgentFaxNo.Text = string.Empty;
        this.txtAgentPhoneNo.Text = string.Empty;
        this.txtAgentPhoneNo2.Text = string.Empty;
        this.txtAgentContactPerson2.Text = string.Empty;
        this.txtAgentFaxNo2.Text = string.Empty;
        this.txtAgentEmailAddress.Text = string.Empty;
        this.txtAgentEmailAddress2.Text = string.Empty;
        this.txtAgentContactPerson3.Text = string.Empty;
        this.txtAgentContactFax3.Text = string.Empty;
        this.txtAgentContactPhone3.Text = string.Empty;
        this.txtAgentContactEmail3.Text = string.Empty;
        this.txtAgentContactPerson4.Text = string.Empty;
        this.txtAgentContactFax4.Text = string.Empty;
        this.txtAgentContactPhone4.Text = string.Empty;
        this.txtAgentContactEmail4.Text = string.Empty;
        this.txtTitleSubject.Text = string.Empty;
        this.txtApplicant.Text = string.Empty;
        this.txtInventor.Text = string.Empty;
        this.txtApplicationNo.Text = string.Empty;
        this.txtPatentNumber.Text = string.Empty;
        this.txtPriorityDate.Text = string.Empty;
        this.ddlPriorityCountry.SelectedIndex = 0;
        this.txtClient.Text = string.Empty;
        this.txtFilingDate.Text = string.Empty;
        this.txtGrantDate.Text = string.Empty;
        this.txtFilingDate.Text = string.Empty;
        this.txtPublicationNumber.Text = string.Empty;
        this.txtRemarks.Text = string.Empty;
        this.txtProjectClass.Text = string.Empty;
        this.chkFirstFiling.Checked = false;
        this.chkPriority.Checked = false;
        this.chkForUpdate.Checked = false;
        this.chkForOperation.Checked = false;
    }

    protected void ddlCountry_PreRender(object sender, EventArgs e)
    {
        try
        {
            if (this.ddlCountry.Text == "")
            {
                Project runMethod = new Project();
                runMethod.GetProjectInfo(this.projectgroupid, this.projectCode, this.projecttype);
                this.ddlCountry.ClearSelection();
                this.ddlCountry.Items.FindByValue(runMethod.Country).Selected = true;
            }
        }
        catch (Exception)
        {
        }
    }

    protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.SetPCT(this.ddlCountry.SelectedValue);
        if (this.chkPCT.Checked & (this.txtType.Text == "Patent"))
        {
            this.txtPriorityDate.Text = this.txtFilingDate.Text;
            this.txtPriorityDate.Enabled = false;
        }
        if (!this.chkPCT.Checked & (this.txtType.Text == "Patent"))
        {
            this.txtPriorityDate.Text = "";
            this.txtPriorityDate.Enabled = true;
        }
        if (this.chkPriority.Checked)
        {
            this.txtPriorityDate.Enabled = false;
        }
    }

    protected void ddlPriorityCountry_PreRender(object sender, EventArgs e)
    {
        try
        {
            if (this.ddlPriorityCountry.Text == "")
            {
                Project runMethod = new Project();
                runMethod.GetProjectInfo(this.projectgroupid, this.projectCode, this.projecttype);
                this.ddlPriorityCountry.SelectedIndex = -1;
                this.ddlPriorityCountry.Items.FindByValue(runMethod.PriorityCountry).Selected = true;
            }
        }
        catch (Exception)
        {
        }
    }

    protected void ddlStatus_PreRender(object sender, EventArgs e)
    {
        try
        {
            if (!this.Page.IsPostBack | (this.ddlStatus.Text == ""))
            {
                if (base.Request.QueryString["np"].ToString() == "0")
                {
                    Project runMethod = new Project();
                    runMethod.GetProjectInfo(this.projectgroupid, this.projectCode, this.projecttype);
                    this.ddlStatus.SelectedIndex = -1;
                    this.ddlStatus.Items.FindByValue(runMethod.Status).Selected = true;
                }
                else
                {
                    this.ddlStatus.SelectedIndex = -1;
                    this.ddlStatus.Items.FindByText("Pending").Selected = true;
                }
            }
        }
        catch (Exception)
        {
        }
    }

    private void EnabledDisabledPriority(string Mode)
    {
        this.chkFirstFiling.Enabled = false;
        if ((this.Session["FirstFilingEnabled"].ToString() == "1") | Convert.ToBoolean(this.Session["SuperUser"].ToString()))
        {
            this.chkFirstFiling.Enabled = true;
            if (this.chkFirstFiling.Checked)
            {
                this.txtFilingDate.Enabled = false;
            }
            else
            {
                this.txtFilingDate.Enabled = true;
            }
        }
        else
        {
            this.chkFirstFiling.Enabled = false;
            this.txtFilingDate.Enabled = false;
        }
        if (!(this.chkFirstFiling.Checked || !(this.Session["FirstFilingEnabled"].ToString() == "0")))
        {
            this.chkFirstFiling.Enabled = false;
            this.txtFilingDate.Enabled = true;
        }
        if ((this.Session["FirstFilingEnabled"].ToString() == "1") | ((this.Session["FirstFilingEnabled"].ToString() == "0") && (this.txtProjectCode.Text.ToString() == this.Session["TargetProjectCode"].ToString())))
        {
            this.txtPriorityDate.Enabled = false;
            this.ddlPriorityCountry.Enabled = false;
        }
        if (Mode == "New")
        {
            this.txtProjectClass.Text = this.Session["ProjectClass"].ToString();
        }
        if (this.txtProjectGroupID.Text == "")
        {
            this.chkFirstFiling.Enabled = false;
            this.txtFilingDate.Enabled = false;
        }
    }

    protected void EnableDisableByProjectType()
    {
        string strname0 = this.projecttype;
        if (strname0 != null)
        {
            if (!(strname0 == "Design"))
            {
                if (strname0 == "Trademark")
                {
                    this.lblInventor.Text = Strings.Inventor.ToString();
                    this.lblPatentNumber.Text = Strings.RegistrationNumber.ToString();
                    this.chkPCT.Visible = false;
                    this.Panel1.Visible = true;
                    this.chkFirstFiling.Visible = true;
                }
                else if (strname0 == "Others")
                {
                    this.lblInventor.Text = Strings.Inventor.ToString();
                    this.lblPatentNumber.Text = Strings.PatentNumber.ToString();
                    this.chkPCT.Visible = false;
                    this.chkFirstFiling.Visible = false;
                    this.Panel1.Visible = false;
                }
                else if (strname0 == "Patent")
                {
                    this.lblInventor.Text = Strings.Inventor.ToString();
                    this.lblPatentNumber.Text = Strings.PatentNumber.ToString();
                    this.chkPCT.Visible = true;
                    this.chkFirstFiling.Visible = true;
                    this.Panel1.Visible = true;
                }
            }
            else
            {
                this.lblInventor.Text = Strings.Designer.ToString();
                this.lblPatentNumber.Text = Strings.RegistrationNumber.ToString();
                this.chkPCT.Visible = false;
                this.chkFirstFiling.Visible = true;
                this.Panel1.Visible = true;
            }
        }
    }

    private void GetProjectDefault()
    {
        byte FilingEnabled;
        DateTime FirstFilingDate;
        DateTime PriorityDate;
        DateTime PCTPriorityDate;
        byte Expired;
        Project pj = new Project();
        string TargetProjectCode = "";
        string ProjectClass = "";
        string PCTCountry = "";
        int intRet = 0;
        this.Session["TargetProjectCode"] = "";
        this.Session["ProjectClass"] = "";
        this.Session["FirstFilingEnabled"] = "";
        this.Session["ProjectClass"] = "";
        this.Session["FirstFilingDate"] = "";
        this.Session["PriorityDate"] = "";
        this.Session["PCTCountry"] = "";
        this.Session["PCTPriorityDate"] = "";
        this.Session["PCTExpired"] = "";
        intRet = pj.CheckProjectFirstFiling(this.txtProjectGroupID.Text.ToString(), "", out TargetProjectCode, out FilingEnabled, out ProjectClass, out FirstFilingDate, out PriorityDate, out PCTCountry, out PCTPriorityDate, out Expired);
        this.Session["TargetProjectCode"] = TargetProjectCode.ToString();
        this.Session["ProjectClass"] = ProjectClass.ToString();
        this.Session["FirstFilingEnabled"] = FilingEnabled.ToString();
        this.Session["ProjectClass"] = ProjectClass.ToString();
        this.Session["FirstFilingDate"] = FirstFilingDate.ToString();
        this.Session["PriorityDate"] = PriorityDate.ToString();
        this.Session["PCTCountry"] = PCTCountry.ToString();
        this.Session["PCTPriorityDate"] = PCTPriorityDate.ToString();
        this.Session["PCTExpired"] = Expired.ToString();
        if (!string.IsNullOrEmpty(this.txtProjectGroupID.Text) && !this.chkForUpdate.Checked)
        {
            ProjectGroupClass runMethod = new ProjectGroupClass();
            runMethod.GetPGDefault(this.txtProjectGroupID.Text);
            try
            {
                this.txtClient.Text = runMethod.Client.ToString();
                this.PopulateClient();
                this.txtTitleSubject.Text = runMethod.TitleSubject.ToString();
                this.txtApplicant.Text = runMethod.Applicant.ToString();
                this.txtInventor.Text = runMethod.Inventor.ToString();
                this.txtProjectClass.Text = runMethod.ProjectClass.ToString();
                this.txtType.Text = runMethod.Type.ToString();
                this.lblError.Text = "";
                this.lblError.Visible = false;

            }
            catch (Exception)
            {
                this.txtProjectGroupID.Text = "";
                this.lblError.Text = Messages.ProjectGroupIDDoesNotExist.ToString();
                this.lblError.Visible = true;
            }
            if (runMethod.Type == "")
            {
                this.txtProjectGroupID.Text = "";
                this.lblError.Text = Messages.ProjectGroupIDDoesNotExist.ToString();
                this.lblError.Visible = true;
            }
        }
    }

    protected void GridToProjectInfo()
    {
        this.txtProjectGroupID.Text = base.Request.QueryString["pgi"].ToString();
        this.txtProjectCode.Text = this.GridView1.DataKeys[this.GridView1.SelectedIndex]["ProjectCode"].ToString();
        this.txtAgent.Text = this.GridView1.DataKeys[this.GridView1.SelectedIndex]["Agent"].ToString();
        this.txtTitleSubject.Text = this.GridView1.DataKeys[this.GridView1.SelectedIndex]["Title"].ToString();
        this.txtApplicant.Text = this.GridView1.DataKeys[this.GridView1.SelectedIndex]["Applicant"].ToString();
        this.txtInventor.Text = this.GridView1.DataKeys[this.GridView1.SelectedIndex]["Inventor"].ToString();
        this.txtApplicationNo.Text = this.GridView1.DataKeys[this.GridView1.SelectedIndex]["ApplicationNo"].ToString();
        this.txtPatentNumber.Text = this.GridView1.DataKeys[this.GridView1.SelectedIndex]["PatentNumber"].ToString();
        this.txtPriorityDate.Text = IPDataFormat.FormatDateTime(this.GridView1.DataKeys[this.GridView1.SelectedIndex]["PriorityDate"].ToString());
        this.txtClient.Text = this.GridView1.DataKeys[this.GridView1.SelectedIndex]["ClientName"].ToString();
        this.txtFilingDate.Text = IPDataFormat.FormatDateTime(this.GridView1.DataKeys[this.GridView1.SelectedIndex]["FilingDate"].ToString());
        this.txtGrantDate.Text = IPDataFormat.FormatDateTime(this.GridView1.DataKeys[this.GridView1.SelectedIndex]["GrantDate"].ToString());
        this.chkFirstFiling.Checked = Convert.ToBoolean(this.GridView1.DataKeys[this.GridView1.SelectedIndex]["FirstFilingYN"].ToString());
        if (this.chkFirstFiling.Checked)
        {
            this.txtFilingDate.CssClass = "required";
            this.RequiredFieldValidator5.Enabled = true;
        }
        else
        {
            this.txtFilingDate.CssClass = "";
            this.RequiredFieldValidator5.Enabled = false;
        }
        this.txtPublicationNumber.Text = this.GridView1.DataKeys[this.GridView1.SelectedIndex]["PublicationNumber"].ToString();
        this.txtRemarks.Text = this.GridView1.DataKeys[this.GridView1.SelectedIndex]["Remark"].ToString();
        this.txtAgentContactPerson3.Text = this.GridView1.DataKeys[this.GridView1.SelectedIndex]["AltContactPerson"].ToString();
        this.txtAgentContactFax3.Text = this.GridView1.DataKeys[this.GridView1.SelectedIndex]["AltContactFax"].ToString();
        this.txtAgentContactPhone3.Text = this.GridView1.DataKeys[this.GridView1.SelectedIndex]["AltContactPerson"].ToString();
        this.txtAgentContactEmail3.Text = this.GridView1.DataKeys[this.GridView1.SelectedIndex]["AltContactEmailAddress"].ToString();
        this.txtProjectClass.Text = this.GridView1.DataKeys[this.GridView1.SelectedIndex]["ProjectClass"].ToString();
        this.chkPriority.Checked = Convert.ToBoolean(this.GridView1.DataKeys[this.GridView1.SelectedIndex]["Priority"].ToString());
        Project runMethod2 = new Project();
        bool superUser = Convert.ToBoolean(this.Session["SuperUser"].ToString());
        runMethod2.GetProjectStatus(this.txtProjectCode.Text.ToString(), superUser, this.Session["OwnerGroupId"].ToString());
        if (runMethod2.Status == "Expired")
        {
            this.btnDelete.Enabled = false;
            this.btnModify.Enabled = false;
        }
        if (this.GridView1.DataKeys[this.GridView1.SelectedIndex]["Status"].ToString().ToLower() == "expired")
        {
            this.PrjInfoPanel.BackColor = ColorTranslator.FromHtml("#C0C0C0");
        }
        else
        {
            this.PrjInfoPanel.BackColor = ColorTranslator.FromHtml("#FFFFFF");
        }
    }

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        this.Sort(e, this.GridView1);
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[10].Text = IPDataFormat.FormatDateTime(e.Row.Cells[10].Text);
            e.Row.Cells[12].Text = IPDataFormat.FormatDateTime(e.Row.Cells[12].Text);
            e.Row.Cells[0x1b].Text = IPDataFormat.FormatDateTime(e.Row.Cells[0x1b].Text);
        }
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.projectCode = this.GridView1.DataKeys[this.GridView1.SelectedIndex].Value.ToString();
        string isDelete = this.GridView1.DataKeys[this.GridView1.SelectedIndex].Values["IsDelete"].ToString();

        ViewState["isRestore"] = false;

        if (Session["SuperUser"] != null)
        {
            if (Convert.ToBoolean(Session["SuperUser"]) && Convert.ToBoolean(isDelete))
            {
                ViewState["isRestore"] = true;
            }
        }

        this.Session["projectCode"] = this.projectCode.ToString();
        this.setButtons(string.Empty);
        this.LoadProjectInfo(base.Request.QueryString["pgi"].ToString(), this.projectCode, this.GridView1.DataKeys[this.GridView1.SelectedIndex]["Type"].ToString());
        this.SetGrantDate();
        this.lbResponsiblePerson.Enabled = base.Request.QueryString["np"].ToString() == "0";
        string culture = this.Session["Culture"].ToString().ToLower();
        this.ibGeneral.ImageUrl = "~/Images/a_General_blue-" + culture + ".gif";
        this.ibAgent.ImageUrl = "~/Images/a_Agent_gray-" + culture + ".gif";
        this.ibClient.ImageUrl = "~/Images/a_client_gray-" + culture + ".gif";
        this.ibOthers.ImageUrl = "~/Images/a_others_gray-" + culture + ".gif";
        this.ibGeneral.Visible = true;
        this.ibAgent.Visible = true;
        this.ibClient.Visible = true;
        this.ibOthers.Visible = true;
    }

    protected void gvChooseProjectClass_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.txtProjectClass.Text = this.gvChooseProjectClass.DataKeys[this.gvChooseProjectClass.SelectedIndex].Values["ProjectClass"].ToString();
    }

    protected void ibAgent_Click(object sender, ImageClickEventArgs e)
    {
        string culture = this.Session["Culture"].ToString().ToLower();
        this.ibGeneral.ImageUrl = "~/Images/a_General_gray-" + culture + ".gif";
        this.ibAgent.ImageUrl = "~/Images/a_Agent_blue-" + culture + ".gif";
        this.ibClient.ImageUrl = "~/Images/a_client_gray-" + culture + ".gif";
        this.ibOthers.ImageUrl = "~/Images/a_others_gray-" + culture + ".gif";
        this.PanelGeneral.Visible = false;
        this.PanelAgent.Visible = true;
        this.PanelClient.Visible = false;
        this.PanelOther.Visible = false;
    }

    protected void ibClient_Click(object sender, ImageClickEventArgs e)
    {
        string culture = this.Session["Culture"].ToString().ToLower();
        this.ibGeneral.ImageUrl = "~/Images/a_General_gray-" + culture + ".gif";
        this.ibAgent.ImageUrl = "~/Images/a_Agent_gray-" + culture + ".gif";
        this.ibClient.ImageUrl = "~/Images/a_client_blue-" + culture + ".gif";
        this.ibOthers.ImageUrl = "~/Images/a_others_gray-" + culture + ".gif";
        this.PanelGeneral.Visible = false;
        this.PanelAgent.Visible = false;
        this.PanelClient.Visible = true;
        this.PanelOther.Visible = false;
    }

    protected void ibExpenditure_Click(object sender, ImageClickEventArgs e)//ImageClickEventArgs
    {
        base.Response.Redirect("Expenses.aspx?pgi=" + this.txtProjectGroupID.Text.ToString() + "&type=" + this.txtType.Text.ToString() + "&pc=" + this.txtProjectCode.Text.ToString() + "&di=0&np=0");
    }

    protected void ibGeneral_Click(object sender, ImageClickEventArgs e)
    {
        string culture = this.Session["Culture"].ToString().ToLower();
        this.ibGeneral.ImageUrl = "~/Images/a_general_blue-" + culture + ".gif";
        this.ibAgent.ImageUrl = "~/Images/a_Agent_gray-" + culture + ".gif";
        this.ibClient.ImageUrl = "~/Images/a_client_gray-" + culture + ".gif";
        this.ibOthers.ImageUrl = "~/Images/a_others_gray-" + culture + ".gif";
        this.PanelGeneral.Visible = true;
        this.PanelAgent.Visible = false;
        this.PanelClient.Visible = false;
        this.PanelOther.Visible = false;
    }

    protected void ibOthers_Click(object sender, ImageClickEventArgs e)
    {
        string culture = this.Session["Culture"].ToString().ToLower();
        this.ibGeneral.ImageUrl = "~/Images/a_General_gray-" + culture + ".gif";
        this.ibAgent.ImageUrl = "~/Images/a_Agent_gray-" + culture + ".gif";
        this.ibClient.ImageUrl = "~/Images/a_client_gray-" + culture + ".gif";
        this.ibOthers.ImageUrl = "~/Images/a_others_blue-" + culture + ".gif";
        if (!this.txtProjectCode.Enabled | this.txtProjectCode.ReadOnly)
        {
            this.Session["ProjectCode"] = this.txtProjectCode.Text;
        }
        this.PanelGeneral.Visible = false;
        this.PanelAgent.Visible = false;
        this.PanelClient.Visible = false;
        this.PanelOther.Visible = true;
    }

    protected void ibProjectHeaderInfo_Click(object sender, ImageClickEventArgs e)//ImageClickEventArgs
    {
        base.Response.Redirect("HeaderInfo.aspx?pgi=" + this.txtProjectGroupID.Text.ToString() + "&type=" + this.txtType.Text.ToString() + "&pc=" + this.txtProjectCode.Text.ToString() + "&di=0&np=0");
    }

    protected void ibProjectInfo_Click(object sender, ImageClickEventArgs e)//ImageClickEventArgs
    {
        base.Response.Redirect("ProjectInfo.aspx?pgi=" + this.txtProjectGroupID.Text.ToString() + "&type=" + this.txtType.Text.ToString() + "&pc=" + this.txtProjectCode.Text.ToString() + "&di=0&np=0");
    }

    protected void ibViewDoc_Click(object sender, ImageClickEventArgs e)
    {
        base.Response.Redirect("ProjectDocument.aspx?pgi=" + this.txtProjectGroupID.Text.ToString() + "&type=" + this.txtType.Text.ToString() + "&pc=" + this.txtProjectCode.Text.ToString() + "&di=0&np=0");
    }

    protected override void InitializeCulture()
    {
        string sCulture = ConfigurationManager.AppSettings["DefaultCulture"].ToString();
        try
        {
            sCulture = this.Session["Culture"].ToString();
        }
        catch (NullReferenceException)
        {
        }
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(sCulture);
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(sCulture);
        base.InitializeCulture();
    }

    protected void lbResponsiblePerson_Click(object sender, EventArgs e)
    {
        this.grdProjectResponsiblePerson.DataBind();
    }

    protected void LoadProjectInfo(string pgi, string pc, string type)
    {
        string culture = this.Session["Culture"].ToString().ToLower();
        this.ibGeneral.ImageUrl = "~/Images/a_General_blue-" + culture + ".gif";
        this.ibAgent.ImageUrl = "~/Images/a_Agent_gray-" + culture + ".gif";
        this.ibClient.ImageUrl = "~/Images/a_client_gray-" + culture + ".gif";
        this.ibOthers.ImageUrl = "~/Images/a_others_gray-" + culture + ".gif";
        this.PanelGeneral.Visible = true;
        this.btnModify.Visible = true;
        this.btnSave.Visible = true;
        this.btnDelete.Visible = true;
        this.btnCancel.Visible = true;

        bool isRestore = false;

        if (ViewState["isRestore"] != null)
        {
            if (Convert.ToBoolean(ViewState["isRestore"]))
            {
                isRestore = true;
            }
        }

        if (isRestore)
        {
            this.setButtons("restore");
        }
        else
        {
            this.setButtons(string.Empty);
        }

        this.PopulateProjectInfo(pgi, pc, type);
        this.EnableDisableByProjectType();
        this.PCTProcess(true);
        this.PrjInfoPanel.Visible = true;
        this.ProjectListPanel.Visible = false;
        this.ibExpenditure.Visible = true;
        this.ibProjectHeaderInfo.Visible = true;
        this.ibProjectInfo.Visible = true;
        this.ibViewDoc.Visible = true;
        this.txtProjectGroupID.Enabled = false;
        this.txtProjectCode.Focus();
        this.setTextReadOnly(true);
    }

    protected void OKProjectClassButton_Click(object sender, EventArgs e)
    {
        if (this.gvChooseProjectClass.SelectedIndex >= 0)
        {
            this.txtProjectClass.Text = this.gvChooseProjectClass.DataKeys[this.gvChooseProjectClass.SelectedIndex].Values["ProjectClass"].ToString();
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        string culture = this.Session["Culture"].ToString().ToLower();
        int iReturn = 0;

        if (!this.Page.IsPostBack)
        {
            this.ibProjectInfo.ImageUrl = "~/Images/p_ProjInfo-" + culture + ".gif";
            this.ibViewDoc.ImageUrl = "~/Images/p_ViewDoc-" + culture + ".gif";
            this.ibProjectHeaderInfo.ImageUrl = "~/Images/p_AppProc-" + culture + ".gif";
            this.ibExpenditure.ImageUrl = "~/Images/p_Finance-" + culture + ".gif";
            this.lblError.Visible = false;
            this.btnDelete.Attributes.Add("onClick", "return confirm('" + Messages.DeleteConfirmation.ToString() + "')");

            if ((base.Request.QueryString["np"].ToString() == "1") && (base.Request.QueryString["di"].ToString() == "0"))
            {
                this.txtProjectGroupID.Text = base.Request.QueryString["pgi"].ToString();
                iReturn = this.Add(sender, e);
                this.txtProjectGroupID.Enabled = true;
                this.txtProjectGroupID.Focus();
                this.PrjInfoPanel.Visible = true;
                this.ProjectListPanel.Visible = false;
                this.ibExpenditure.Visible = true;
                this.ibProjectHeaderInfo.Visible = true;
                this.ibProjectInfo.Visible = true;
                this.ibViewDoc.Visible = true;
                this.ibGeneral.ImageUrl = "~/Images/a_General_blue-" + culture + ".gif";
                this.ibAgent.ImageUrl = "~/Images/a_Agent_gray-" + culture + ".gif";
                this.ibClient.ImageUrl = "~/Images/a_client_gray-" + culture + ".gif";
                this.ibOthers.ImageUrl = "~/Images/a_others_gray-" + culture + ".gif";
                this.PanelGeneral.Visible = true;
                this.btnModify.Visible = true;
                this.btnSave.Visible = true;
                this.btnDelete.Visible = true;
                this.btnCancel.Visible = true;
                this.projecttype = this.txtType.Text;
                this.setButtons("new");

                if (iReturn != 0)
                {
                    this.btnSave.Visible = false;
                }
            }
            else
            {
                try
                {
                    this.projectgroupid = base.Request.QueryString["pgi"].ToString();
                    this.projectCode = base.Request.QueryString["pc"].ToString();
                    this.projecttype = base.Request.QueryString["type"].ToString();

                    if (string.IsNullOrEmpty(this.projectgroupid))
                    {
                        try
                        {
                            this.projectgroupid = base.Request.QueryString["projectGroupId"].ToString();
                            this.projectCode = base.Request.QueryString["projectCode"].ToString();
                            this.projecttype = base.Request.QueryString["projectType"].ToString();
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                catch (NullReferenceException)
                {
                }

                if (string.IsNullOrEmpty(this.projectCode))
                {
                    this.ibGeneral.Visible = false;
                    this.ibAgent.Visible = false;
                    this.ibClient.Visible = false;
                    this.ibOthers.Visible = false;
                    this.btnModify.Visible = false;
                    this.btnSave.Visible = false;
                    this.btnDelete.Visible = false;
                    this.btnCancel.Visible = false;
                    this.PrjInfoPanel.Visible = false;
                    this.ProjectListPanel.Visible = true;
                    this.ibExpenditure.Visible = false;
                    this.ibProjectHeaderInfo.Visible = false;
                    this.ibProjectInfo.Visible = false;
                    this.ibViewDoc.Visible = false;
                    this.GridView1.DataBind();
                    if (this.GridView1.Rows.Count == 0)
                    {
                        this.lblNoRecords.Visible = true;
                    }
                    else
                    {
                        this.lblNoRecords.Visible = false;
                    }
                }
                else
                {
                    ViewState["isRestore"] = false;

                    if (Session["SuperUser"] != null && base.Request.QueryString["isd"] != null)
                    {
                        if (Convert.ToBoolean(Session["SuperUser"]) && base.Request.QueryString["isd"].ToString() == "1")
                        {
                           ViewState["isRestore"] = true;
                        }
                    }

                    this.LoadProjectInfo(base.Request.QueryString["pgi"].ToString(), this.projectCode, base.Request.QueryString["type"].ToString());
                }
            }
        }

        this.SetGrantDate();
        this.lblError.Text = "";
        this.lbResponsiblePerson.Enabled = base.Request.QueryString["np"].ToString() == "0";
    }

    protected void PCTProcess(bool bPCTDisabled)
    {
        if ((this.projecttype == "Patent") | (this.txtType.Text == "Patent"))
        {
            if (!this.txtProjectCode.Enabled)
            {
                if (!this.chkPCT.Checked)
                {
                    this.chkPCT.Enabled = true;
                }
                if (Convert.ToBoolean(this.Session["SuperUser"].ToString()) & this.chkPCT.Checked)
                {
                    this.chkPCT.Enabled = true;
                }
                if ((!Convert.ToBoolean(this.Session["SuperUser"].ToString()) & this.chkPCT.Checked) && bPCTDisabled)
                {
                    this.chkPCT.Enabled = false;
                }
            }
            else
            {
                this.chkPCT.Enabled = true;
            }
            if (!this.chkPCT.Checked)
            {
                this.txtPriorityDate.Enabled = true;
            }
            else if (this.txtProjectCode.Enabled)
            {
                this.txtPriorityDate.Enabled = true;
            }
            else if (this.txtPriorityDate.Text != "")
            {
                this.txtPriorityDate.Enabled = false;
            }
            else
            {
                this.txtPriorityDate.Enabled = true;
            }
            if (this.chkPriority.Checked)
            {
                this.txtPriorityDate.Enabled = false;
            }
        }
    }

    protected void PopulateClient()
    {
        Client client = new Client(this.txtClient.Text.ToString());
        client.GetClientDetails();
        this.txtClientName.Text = client.Client_Name;
        this.txtClientChineseName.Text = client.Client_ChineseName;
        this.txtClientContactPerson.Text = client.Client_ContactPerson;
        this.txtClientAddress.Text = client.Client_Address;
        this.txtClientWebSite.Text = client.Client_WebSite;
        this.txtClientFax.Text = client.Client_Fax;
        this.txtClientPhone.Text = client.Client_Phone;
        this.txtClientPhone2.Text = client.Client_Phone2;
        this.txtClientContactPerson2.Text = client.Client_ContactPerson2;
        this.txtClientFax2.Text = client.Client_Fax2;
        this.txtClientEmailAddress.Text = client.Client_EmailAddress;
        this.txtClientEmailAddress2.Text = client.Client_EmailAddress2;
    }

    private void PopulateProjectInfo(string pgi, string projectCode, string type)
    {
        if ((this.GridView1.Rows.Count == 0) && this.ProjectListPanel.Visible)
        {
            this.PrjInfoPanel.Visible = false;
            this.ProjectListPanel.Visible = true;
            this.ibExpenditure.Visible = false;
            this.ibProjectHeaderInfo.Visible = false;
            this.ibProjectInfo.Visible = false;
            this.ibViewDoc.Visible = false;
            this.GridView1.DataBind();
            if (this.GridView1.Rows.Count == 0)
            {
                this.lblNoRecords.Visible = true;
            }
            else
            {
                this.lblNoRecords.Visible = false;
            }
        }
        else
        {
            Project runMethod = new Project();
            if (string.IsNullOrEmpty(this.projectgroupid))
            {
                this.projectgroupid = pgi;
            }
            if (string.IsNullOrEmpty(this.projecttype))
            {
                this.projecttype = type;
            }
            if (string.IsNullOrEmpty(this.projecttype))
            {
                this.projecttype = this.GridView1.Rows[this.GridView1.SelectedIndex].Cells[2].Text.ToString();
            }
            runMethod.GetProjectInfo(this.projectgroupid, projectCode, this.projecttype);
            this.txtProjectGroupID.Text = this.projectgroupid;
            this.txtProjectCode.Text = projectCode;
            this.txtAgent.Text = runMethod.Agent;
            this.txtType.Text = this.projecttype;
            this.txtTitleSubject.Text = runMethod.Title;
            this.txtApplicant.Text = runMethod.Applicant;
            this.txtInventor.Text = runMethod.Inventor;
            this.txtApplicationNo.Text = runMethod.ApplicantNumber;
            this.txtPatentNumber.Text = runMethod.PatentNumber;
            this.txtPriorityDate.Text = IPDataFormat.FormatDateTime(runMethod.PriorityDate);
            this.txtClient.Text = runMethod.ClientName;
            this.txtFilingDate.Text = IPDataFormat.FormatDateTime(runMethod.FilingDate);
            this.txtGrantDate.Text = IPDataFormat.FormatDateTime(runMethod.GrantDate);
            this.chkFirstFiling.Checked = runMethod.FirstFilingYN;
            this.chkPCT.Checked = runMethod.PCTYN;
            if (this.chkFirstFiling.Checked)
            {
                this.txtFilingDate.CssClass = "required";
                this.RequiredFieldValidator5.Enabled = true;
            }
            else
            {
                this.txtFilingDate.CssClass = "";
                this.RequiredFieldValidator5.Enabled = false;
            }
            this.txtPublicationNumber.Text = runMethod.PublicationNumber;
            this.txtRemarks.Text = runMethod.Remarks;
            this.txtAgentContactPerson3.Text = runMethod.AgentContactPerson3;
            this.txtAgentContactFax3.Text = runMethod.AgentContactFax3;
            this.txtAgentContactPhone3.Text = runMethod.AgentContactPhone3;
            this.txtAgentContactEmail3.Text = runMethod.AgentContactEmail3;
            this.txtAgentContactPerson4.Text = runMethod.AgentContactPerson4;
            this.txtAgentContactFax4.Text = runMethod.AgentContactFax4;
            this.txtAgentContactPhone4.Text = runMethod.AgentContactPhone4;
            this.txtAgentContactEmail4.Text = runMethod.AgentContactEmail4;
            this.txtClientContactPerson3.Text = runMethod.ClientContactPerson3;
            this.txtClientContactFax3.Text = runMethod.ClientContactFax3;
            this.txtClientContactPhone3.Text = runMethod.ClientContactPhone3;
            this.txtClientContactEmail3.Text = runMethod.ClientContactEmail3;
            this.txtClientContactPerson4.Text = runMethod.ClientContactPerson4;
            this.txtClientContactFax4.Text = runMethod.ClientContactFax4;
            this.txtClientContactPhone4.Text = runMethod.ClientContactPhone4;
            this.txtClientContactEmail4.Text = runMethod.ClientContactEmail4;
            this.txtProjectClass.Text = runMethod.ProjectClass;
            this.chkPriority.Checked = runMethod.Priority;
            Project runMethod2 = new Project();
            bool superUser = Convert.ToBoolean(this.Session["SuperUser"].ToString());
            runMethod2.GetProjectStatus(this.txtProjectCode.Text.ToString(), superUser, this.Session["OwnerGroupId"].ToString());

            if (runMethod2.Status == "Expired")
            {
                this.btnDelete.Enabled = false;
                this.btnModify.Enabled = false;
            }

            if (runMethod.Status == "Expired")
            {
                this.PrjInfoPanel.BackColor = ColorTranslator.FromHtml("#C0C0C0");
            }
            else
            {
                this.PrjInfoPanel.BackColor = ColorTranslator.FromHtml("#FFFFFF");
            }

            if (this.txtAgent.Text != "")
            {
                Agent agent = new Agent(this.txtAgent.Text.ToString());
                agent.GetAgentDetails();
                this.txtAgentName.Text = agent.Agent_Name;
                this.txtAgentChineseName.Text = agent.Agent_ChineseName;
                this.txtAgentContactPerson.Text = agent.Agent_ContactPerson;
                this.txtAgentAddress.Text = agent.Agent_Address;
                this.txtAgentWebSite.Text = agent.Agent_WebSite;
                this.txtAgentFaxNo.Text = agent.Agent_Fax;
                this.txtAgentPhoneNo.Text = agent.Agent_Phone;
                this.txtAgentPhoneNo2.Text = agent.Agent_Phone2;
                this.txtAgentContactPerson2.Text = agent.Agent_ContactPerson2;
                this.txtAgentFaxNo2.Text = agent.Agent_Fax2;
                this.txtAgentEmailAddress.Text = agent.Agent_EmailAddress;
                this.txtAgentEmailAddress2.Text = agent.Agent_EmailAddress2;
            }
            if (this.txtClient.Text != "")
            {
                this.PopulateClient();
            }
            this.setTextReadOnly(false);
        }
    }

    public void setButtons(string action)
    {
        switch (action)
        {
            case "new":
                this.btnNew.Enabled = false;
                this.btnModify.Enabled = false;
                this.btnSave.Enabled = true;
                this.btnDelete.Enabled = false;
                this.btnRestore.Visible = false;
                this.EnableDisableByProjectType();
                return;

            case "modify":
                this.btnNew.Enabled = false;
                this.btnModify.Enabled = false;
                this.btnSave.Enabled = true;
                this.btnDelete.Enabled = false;
                this.btnRestore.Visible = false;
                return;
            case "restore":
                this.btnNew.Enabled = false;
                this.btnModify.Enabled = false;
                this.btnSave.Enabled = false;
                this.btnDelete.Visible = false;
                this.btnRestore.Visible = true;
                return;

        }
        this.btnNew.Enabled = true;
        this.btnModify.Enabled = true;
        this.btnSave.Enabled = false;
        this.btnDelete.Enabled = true;
        this.btnRestore.Visible = false;
    }

    protected void SetGrantDate()
    {
        if (this.txtPatentNumber.Text.Length != 0)
        {
            this.txtGrantDate.ReadOnly = false;
            this.txtGrantDate.BackColor = ColorTranslator.FromHtml("#FFFFC0");
            if (this.txtGrantDate.Text.Length == 0)
            {
                this.txtGrantDate.Text = IPDataFormat.ConvertDateFormat(DateTime.Now.ToShortDateString(), 2);
            }
        }
        else
        {
            this.txtGrantDate.Text = string.Empty;
        }
    }

    private void SetPCT(string strCountry)
    {
        if (strCountry.ToString() != "")
        {
            try
            {
                if (this.chkPCT.Enabled)
                {
                    this.chkPCT.Checked = new Country().GetPCT(strCountry.ToString());
                }
            }
            catch (Exception)
            {
                this.chkPCT.Checked = false;
            }
        }
    }

    private void setTextReadOnly(bool bBool)
    {
        this.txtProjectGroupID.ReadOnly = bBool;
        this.txtProjectCode.ReadOnly = bBool;
        this.btnPGI.Enabled = !bBool;
        if (this.chkForUpdate.Checked)
        {
        }
        this.ddlStatus.Enabled = !bBool;
        this.ddlCountry.Enabled = !bBool;
        this.btnAgent.Enabled = !bBool;
        this.txtTitleSubject.ReadOnly = bBool;
        this.txtApplicant.ReadOnly = bBool;
        this.txtInventor.ReadOnly = bBool;
        this.txtApplicationNo.ReadOnly = bBool;
        this.txtPatentNumber.ReadOnly = bBool;
        this.txtPriorityDate.Enabled = false;
        this.ddlPriorityCountry.Enabled = false;
        this.btnClient.Enabled = !bBool;
        this.txtAgentContactPerson3.Enabled = !bBool;
        this.txtAgentContactFax3.Enabled = !bBool;
        this.txtAgentContactPhone3.Enabled = !bBool;
        this.txtAgentContactEmail3.Enabled = !bBool;
        this.txtAgentContactPerson4.Enabled = !bBool;
        this.txtAgentContactFax4.Enabled = !bBool;
        this.txtAgentContactPhone4.Enabled = !bBool;
        this.txtAgentContactEmail4.Enabled = !bBool;
        this.txtFilingDate.Enabled = !bBool;
        this.txtGrantDate.Enabled = !bBool;
        this.txtPublicationNumber.ReadOnly = bBool;
        this.txtRemarks.ReadOnly = bBool;
        this.txtProjectClass.ReadOnly = bBool;
        this.btnProjectClass.Enabled = !bBool;
        this.chkFirstFiling.Enabled = !bBool;
        this.chkPriority.Enabled = !bBool;
        this.chkPCT.Enabled = !bBool;
    }

    protected void showRow()
    {
        string showRow_javaScript = "<script type='text/javascript' language='javascript'> \n";
        showRow_javaScript = ((showRow_javaScript + "if (" + base.Request.QueryString["np"].ToString() + "==1) { \n") + "   document.getElementById('PGID').style.display = 'inline'; } \n" + " else { \n") + "   document.getElementById('PGID').style.display = 'none';  \n" + "} </script>";
        base.ClientScript.RegisterStartupScript(this.Page.GetType(), "regShowRow", showRow_javaScript);
    }

    protected void Sort(GridViewRowEventArgs e, GridView gv)
    {
        if ((e.Row != null) && (e.Row.RowType == DataControlRowType.Header))
        {
            foreach (TableCell cell in e.Row.Cells)
            {
                if (cell.HasControls())
                {
                    LinkButton button = (LinkButton) cell.Controls[0];
                    if (button != null)
                    {
                        System.Web.UI.WebControls.Image image = new System.Web.UI.WebControls.Image();
                        image.ImageUrl = "";
                        if (gv.SortExpression == button.CommandArgument)
                        {
                            if (gv.SortDirection == SortDirection.Ascending)
                            {
                                image.ImageUrl = "images/sortup.gif";
                            }
                            else
                            {
                                image.ImageUrl = "images/sortdown.gif";
                            }
                        }
                        if (image.ImageUrl != "")
                        {
                            cell.Controls.Add(image);
                        }
                    }
                }
            }
        }
    }

    protected void txtClientPhone4_TextChanged(object sender, EventArgs e)
    {
    }

    protected void txtFilingDate_TextChanged(object sender, EventArgs e)
    {
    }

    protected void txtGrantDate_TextChanged(object sender, EventArgs e)
    {
        if (this.txtGrantDate.Text.Length != 0)
        {
            this.ddlStatus.SelectedIndex = -1;
            this.ddlStatus.Items.FindByText("In Force").Selected = true;
        }
        else if (this.txtPatentNumber.Text.Length == 0)
        {
            this.ddlStatus.SelectedIndex = -1;
        }
    }

    protected void txtPatentNumber_TextChanged(object sender, EventArgs e)
    {
        this.SetGrantDate();
        if (this.txtPatentNumber.Text.Length != 0)
        {
            this.ddlStatus.SelectedIndex = -1;
            this.ddlStatus.Items.FindByText("In Force").Selected = true;
        }
    }

    protected void txtProjectGroupID_TextChanged(object sender, EventArgs e)
    {
        if (this.txtProjectGroupID.Text != "")
        {
            this.GetProjectDefault();
            this.EnabledDisabledPriority("New");
        }
    }
   
}
